package com.daluzy.chmanager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.daluzy.chmanager.R;
import com.daluzy.chmanager.a_interface.RecyclerViewItemOnClickListener;
import com.daluzy.chmanager.bean.Employee;
import com.daluzy.chmanager.bean.Students;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.MyViewHolder> {



    private Context context;
    private List<Students> myData = new ArrayList<>();
    private RecyclerViewItemOnClickListener<Students> itemOnClickListener;

    public void setItemOnClickListener(RecyclerViewItemOnClickListener<Students> itemOnClickListener) {
        this.itemOnClickListener = itemOnClickListener;
    }

    public StudentAdapter(Context context, List<Students> myData) {
        this.context = context;
        this.myData = myData;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_student_item_daluzy, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        Students students = myData.get(position);
        holder.tvStudentName.setText(String.format("姓名：%s", students.getStudent_name()));
        holder.tvStudentPhone.setText(students.getStudent_phone());
        holder.tvStudentSex.setText(students.getStudent_sex());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemOnClickListener.itemOnClick(students,position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return myData.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_student_name)
        TextView tvStudentName;
        @BindView(R.id.tv_student_sex)
        TextView tvStudentSex;
        @BindView(R.id.tv_student_phone)
        TextView tvStudentPhone;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
